from PyQt4 import QtGui, QtCore

from execute_plugin_widget import ExecutePlugin

class ShowPlugins(QtGui.QDialog):
    
    def __init__(self, parent):
        QtGui.QDialog.__init__(self, parent)
        lang = parent.lang
        self.setWindowTitle(lang['plugins'])
        v_box = QtGui.QVBoxLayout(self)
        
        self._plugins = parent.pytv.plugins
        self._plugList = QtGui.QListWidget()
        for plug in self._plugins.get_active_show_plugins():
            icon = QtGui.QIcon(parent.pytv.pluginFolder + plug[0])
            self._plugList.addItem(QtGui.QListWidgetItem(icon, plug[1]))
        
        v_box.addWidget(QtGui.QLabel(lang['pressPlugin']))
        v_box.addWidget(self._plugList)
        v_box.addWidget(QtGui.QLabel(lang['onlyPlugin']))
        
        self.connect(self._plugList, QtCore.SIGNAL("itemSelectionChanged()"), self._list_clicked)
        
    def _list_clicked(self):
        name = str(self._plugList.item(self._plugList.currentRow()).text())
        widget = self._plugins.show(name)
        executor = ExecutePlugin(self, widget)
        executor.show()
        self.hide()

    def closeEvent(self, event):
        event.ignore()
        self.done(0)
